package com.jds.test.bio.p8;

/**
 * https://www.cnblogs.com/silyvin/articles/12037918.html
 * Created by joyce on 2019/11/26.
 */
import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {

    public static final int PORT = 12123;
    public static final int BUFFER_SIZE = 500;

    public static void main(String [] f) throws IOException, InterruptedException {
        new Server().server();
    }

    //服务端代码
    public void server() throws IOException, InterruptedException{

     //   ServerSocket ss = new ServerSocket(PORT);
        ServerSocket ss = new ServerSocket();
        System.out.println(ss.getReceiveBufferSize());
        ss.setReceiveBufferSize(100);
        InetAddress bindAddr = null;
        ss.bind(new InetSocketAddress(bindAddr, PORT), 50);

        while(true) {
            Socket s = ss.accept();
            System.out.println(s.getRemoteSocketAddress().toString());

            InputStream inputStream = s.getInputStream();
            byte [] bytes = new byte[BUFFER_SIZE];
            int i=0;
            while (inputStream.read(bytes) != -1) {
                System.out.println(i++);
            }

        }
    }
}